<template>
  <back-dialog-base
    @close="close"
    @onCommit="handleSubmit"
    :title="title"
    :visible="visibleDialog"
    width="446px"
  >
    <template #content>
      <div class="content-warp">
        <div class="left-form">
          <el-form
            ref="formRef"
            :model="form"
            :rules="rules"
            label-width="120px"
          >
            <el-form-item label="出廊时间：" prop="endTime">
              <el-date-picker
                v-model="form.endTime"
                type="date"
                value-format="YYYY-MM-DD HH:mm:ss"
                placeholder="--请选择--"
              />
            </el-form-item>
          </el-form>
        </div>
      </div>
    </template>
  </back-dialog-base>
</template>

<script setup>
import { reactive, defineProps, ref, defineEmits, watch } from 'vue'
import BackDialogBase from '@/components/BackDialogBase'
import { message } from '@/utils/message'
import { DutyManagementSave } from '@/api/dutyManagement'

const props = defineProps({
  title: {
    type: String,
    default: ''
  },
  visibleDialog: {
    type: Boolean,
    default: false
  },
  rowData: {
    type: Object,
    default: () => {}
  }
})

const formRef = ref(null)
const emits = defineEmits(['onReload'])
const form = reactive({
  endTime: '', //出廊时间
  id: ''
})
const close = () => {
  formRef.value.resetFields()
}
const save = async (data) => {
  const res = await DutyManagementSave(data)
  if (res && res.id) {
    if (props.title === '新增出廊时间') {
      message({ type: 'success', message: '新增出廊时间成功!' })
    }
    // clearForm()
    emits('onReload')
  }
}
const handleSubmit = () => {
  formRef.value.validate((valid) => {
    if (valid) {
      console.log(props.rowData)
      // save(Object.assign(props.rowData, form))
      save(form)
    } else {
      return false
    }
  })
}
watch(
  () => props.rowData,
  () => {
    form.id = props.rowData.id
  }
)
const rules = reactive({
  endTime: [
    {
      required: true,
      message: '出廊时间不能为空',
      trigger: 'blur'
    }
  ]
})
</script>
<style lang="scss" scoped>
.content-warp {
  :deep(.el-input__inner) {
    width: 212px;
  }
  width: 100%;
  height: 100%;
  display: flex;
  .left-form {
    flex: 4;
  }
}
</style>
